home *** CD-ROM | disk | FTP | other *** search
- head 1.2;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @@;
-
-
- 1.2
- date 90.07.08.16.01.43; author shirriff; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 90.06.22.17.32.33; author shirriff; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.2
- log
- @Unix version 5.9
- @
- text
- @.\" Copyright (c) 1988 The Regents of the University of California.
- .\" All rights reserved.
- .\"
- .\" Redistribution and use in source and binary forms are permitted
- .\" provided that the above copyright notice and this paragraph are
- .\" duplicated in all such forms and that any documentation,
- .\" advertising materials, and other materials related to such
- .\" distribution and use acknowledge that the software was developed
- .\" by the University of California, Berkeley. The name of the
- .\" University may not be used to endorse or promote products derived
- .\" from this software without specific prior written permission.
- .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- .\"
- .\" @@(#)getpwent.3 6.5 (Berkeley) 2/23/89
- .\"
- .TH GETPWENT 3 "February 23, 1989"
- .AT 3
- .SH NAME
- getpwent, getpwnam, getpwuid, setpassent,
- setpwfile, setpwent, endpwent \- get password file entries
- .SH SYNOPSIS
- .nf
- .B #include <sys/types.h>
- .B #include <pwd.h>
- .PP
- .B struct passwd *getpwent()
- .PP
- .B struct passwd *getpwnam(login)
- .B char *login;
- .PP
- .B struct passwd *getpwuid(uid)
- .B uid_t uid;
- .PP
- .B int setpassent(stayopen)
- .B int stayopen;
- .PP
- .B void setpwfile(file)
- .B char *file;
- .PP
- .B int setpwent()
- .PP
- .B void endpwent()
- .fi
- .SH DESCRIPTION
- .IR Getpwent ,
- .IR getpwuid ,
- and
- .I getpwnam
- each return a pointer to a structure containing the broken-out
- fields of a line in the password file. This structure is defined
- by the include file
- .IR < pwd.h > ,
- and contains the following fields:
- .PP
- .RS
- .nf
- struct passwd {
- char *pw_name; /* user name */
- char *pw_passwd; /* encrypted password */
- uid_t pw_uid; /* user uid */
- gid_t pw_gid; /* user gid */
- time_t pw_change; /* password change time */
- char *pw_class; /* user access class */
- char *pw_gecos; /* Honeywell login info */
- char *pw_dir; /* home directory */
- char *pw_shell; /* default shell */
- time_t pw_expire; /* account expiration */
- };
- .fi
- .RE
- .PP
- These fields are more completely described in
- .IR passwd (5).
- .PP
- .I Getpwnam
- and
- .I getpwuid
- search the password database for a matching user name or user uid,
- respectively, returning the first one encountered. Identical
- user names or user uids may result in undefined behavior.
- .PP
- .I Getpwent
- sequentially reads the password database and is intended for programs
- that wish to step through the complete list of users.
- .PP
- All three routines will open the password file for reading, if
- necessary.
- .PP
- .I Setpwfile
- changes the default password file to
- .IR file ,
- thus allowing the use of alternate password files.
- .PP
- .I Setpassent
- opens the file or rewinds it if it is already open. If
- .I stayopen
- is non-zero, file descriptors are left open, significantly speeding
- up subsequent calls. This functionality is unnecessary for
- .I getpwent
- as it doesn't close its file descriptors by default. It should also
- be noted that it is dangerous for long-running programs to use this
- functionality as the password file may be updated by
- .IR chpass (1),
- .IR passwd (1),
- or
- .IR vipw (8).
- .PP
- .I Setpwent
- is identical to
- .I setpassent
- with an argument of zero.
- .PP
- .I Endpwent
- closes any open files.
- .PP
- These routines have been written to ``shadow'' the password file, e.g.
- allow only certain programs to have access to the encrypted password.
- This is done by using the
- .IR mkpasswd (8)
- program, which creates
- .IR ndbm (3)
- databases that correspond to the password file, with the single exception
- that, rather than storing the encrypted password in the database, it stores
- the offset in the password file where the encrypted password may be found.
- .IR Getpwent ,
- .IR getpwnam ,
- and
- .I getpwuid
- will use the
- .I ndbm
- files in preference to the ``real'' password files, only reading the
- password file itself, to obtain the encrypted password, if the process
- is running with an effective user id equivalent to super-user.
- If the password file itself is protected, and the
- .I ndbm
- files are not, this makes the password available only to programs
- running with super-user privileges.
- .SH FILES
- /etc/passwd
- .SH "SEE ALSO"
- getlogin(3), getgrent(3), ndbm(3), passwd(5)
- .SH DIAGNOSTICS
- The routines
- .IR getpwent ,
- .IR getpwnam ,
- and
- .IR getpwuid ,
- return a null pointer on EOF or error.
- .I Setpassent
- and
- .I setpwent
- return 0 on failure and 1 on success.
- .I Endpwent
- and
- .I setpwfile
- have no return value.
- .SH BUGS
- All information is contained in a static buffer which is overwritten
- by each new call. It must be copied elsewhere to be retained.
- .PP
- Intermixing calls to
- .IR getpwent
- with calls to
- .I getpwnam
- or
- .IR getpwuid ,
- or intermixing calls to
- .I getpwnam
- and
- .IR getpwuid ,
- after using
- .I setpassent
- to require that file descriptors be left open, may result
- in undefined behavior.
- .PP
- The routines
- .IR getpwent ,
- .IR endpwent ,
- .IR setpassent ,
- and
- .IR setpwent
- are fairly useless in a networked environment and should be
- avoided, if possible.
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d1 2
- a2 1
- .\" @@(#)getpwent.3 6.3 (Berkeley) 5/15/86
- d4 15
- a18 1
- .TH GETPWENT 3 "May 15, 1986"
- d21 2
- a22 1
- getpwent, getpwuid, getpwnam, setpwent, endpwent, setpwfile \- get password file entry
- d25 1
- d28 5
- d34 1
- a34 4
- .B int uid;
- .PP
- .B struct passwd *getpwnam(name)
- .B char *name;
- d36 2
- a37 1
- .B struct passwd *getpwent()
- d39 2
- a40 1
- .B setpwent()
- d42 1
- a42 1
- .B endpwent()
- d44 1
- a44 2
- .B setpwfile(name)
- .B char *name;
- d47 2
- a48 2
- .I Getpwent,
- .I getpwuid
- d51 6
- a56 4
- each return a pointer to an object with the
- following structure
- containing the broken-out
- fields of a line in the password file.
- a57 1
- .PP
- d59 12
- a70 3
- .so /usr/include/pwd.h
- .ft R
- .ad
- d74 1
- a74 5
- The fields
- .I pw_quota
- and
- .I pw_comment
- are unused; the others have meanings described in
- d77 1
- a77 7
- Searching of the password file is done using the \fIndbm\fP
- database access routines.
- .I Setpwent
- opens the database;
- .I endpwent
- closes it.
- .I Getpwuid
- d79 8
- a86 6
- .I getpwnam
- search the database (opening it if necessary) for a matching
- .I uid
- or
- .IR name .
- EOF is returned if there is no entry.
- d88 2
- a89 9
- For programs wishing to read the entire database,
- .I getpwent
- reads the next
- line (opening the database if necessary).
- In addition to opening the database,
- .I setpwent
- can be used to make
- .I getpwent
- begin its search from the beginning of the database.
- d93 47
- a139 8
- .I name
- thus allowing alternate password files to be used.
- Note that it does
- .I not
- close the previous file.
- If this is desired,
- .I endpwent
- should be called prior to it.
- d143 1
- a143 1
- getlogin(3), getgrent(3), passwd(5)
- d147 2
- d150 6
- d157 2
- a158 2
- .IR getpwnam ,
- return a null pointer (0) on EOF or error.
- d160 26
- a185 4
- All information
- is contained in a static area
- so it must be copied if it is
- to be saved.
- @
-